
<meta http-equiv="content-type" content="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" href="public/css/css.css">
<?php 
if (isset($_POST['submit'])) {
    echo '.........';
    var_dump($_POST);
    echo '.........';
}
?>
<?php
require_once './model/db.php';
$query = " SELECT * FROM pages";
$pages = getPage($query);
$companies=getCompanys(" SELECT * FROM companies");
$keyword = NULL;
$ratingMin = NULL;
$ratingMax = NULL;
?>
<form method="POST">
    Keyword : <input type="text" name="keyword">.<br>
    Company : <select name="id_company" style="width: 200px;">
         <?php foreach ($companies as $company): ?>
       
            <option value="<?php echo $company['id'] ?>"><?php echo $company["name"] ?></option>
        <?php endforeach; ?>
    </select> <br>
    
    App  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:  <select name="id_app">
        <option value="0"><?php echo "App" ?></option>
        <?php 
        $query = 'SELECT * FROM apps;';
        $apps = query($query);
        ?>
        <?php foreach ($apps as $app): ?>
            <option value="<?php echo $app['id']?>"><?php echo $app["name"] ?></option>
        <?php endforeach; ?>
    </select> <br>
    Max Page :   <input type="text" name="max">.<br>
    Min Page :   <input type="text" name="min">.<br>
    <input type="submit" name="submit" value="Search">
</form>
<?php if (isset($_POST['submit'])):?>
<?php 
$q = "SELECT * FROM pages
    INNER JOIN apps_pages ON apps_pages.id_page = pages.id 
    INNER JOIN apps ON apps.id = apps_pages.id_app
    INNER JOIN companies ON companies.id = apps.id_company
    WHERE (apps.id_company =Company ) AND (apps.id = App)" ;
?>
<?php $keyword = $_POST['keyword']; ?>
<?php $min = (double) $_POST['min']; ?>
<?php $max = (double) $_POST['max']; ?>

<table border = "1"> 
    <tr>
        <td>Pid</td>
        <td>picture</td>
        <td>Id</td>
        <td>Name</td>
        <td>Username</td>
        <td>Phone</td>
        <td>Likes</td>
        <td>Talking_about_count</td>                                                          
         <td>Category</td>
          <td>Link</td>
         
        
            
        
    </tr>
    
    <?php foreach ($pages as $page): ?>
    
    <?php if ((int)$_GET.$page['likes']>= ((int)$_POST['min'])&&
            (int)$_GET.$page['likes']<= ((int)$_POST['max'])):?>
            
    <tr>
        <td><?php echo $page['pid']?></td>
        <td><img src='<?php echo $page["picture"]?>'</td>
        <td><?php echo $page['id']?></td>
        <td><?php echo $page['name']?></td>
        <td><?php echo $page['username']?></td>
        <td><?php echo $page['phone']?></td>
        <td><?php echo $page['likes']?></td>
        <td><?php echo $page['talking_about_count']?></td>
        <td><?php echo $page['category']?></td>
        <td><a href='<?php echo $page["link"]?>'><?php echo $page["link"]?></td>
        
        
       
    </tr>  
        <?php endif;?>
    <?php endforeach; ?>
   
</table>
 <?php endif;?>